package com.home.databinding2

import android.util.Log
import androidx.databinding.BaseObservable
import androidx.databinding.ObservableField

class TwoWayBindingViewModel2 {

    /*private var userName: ObservableField<MyData> = ObservableField()
    private var pwd: ObservableField<String> = ObservableField()

    fun getUserName(): String? {
        Log.e("zzm debug", "getUserName:${userName.get()}")
        return userName.get()?.userName
    }

    fun setUserName(str: String) {
        userName.set(MyData(str,null))
        Log.e("zzm debug", "setUserName:$str  |  "+userName.get().toString())
    }

    fun getPwd(): String? {
        Log.e("zzm debug", "getPwd:${pwd.get()}")
        return pwd.get()
    }

    fun setPwd(str:String){
        Log.e("zzm debug", "setPwd:$str")
        pwd.set(str)
    }*/

    private var myData: ObservableField<MyData> = ObservableField()

    fun getUserName(): String? {
        Log.e("zzm debug", "getUserName:${myData.get()?.userName}")
        return myData.get()?.userName
    }

    fun setUserName(str: String) {
        Log.e("zzm debug", "setUserName:$str")
        myData.set(MyData(str,myData.get()?.pwd))
        Log.e("zzm debug","setUserName" + myData.get()?.userName)
    }

    fun getPwd(): String? {
        Log.e("zzm debug", "getPwd:${myData.get()?.pwd}")
        return myData.get()?.pwd
    }

    fun setPwd(str:String){
        Log.e("zzm debug", "setPwd:$str")
        myData.set(MyData(myData.get()?.userName,str))
        Log.e("zzm debug","setPwd" + myData.get()?.pwd)
    }
}